package com.tanhua.test;


import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class Sample {

    /**
     * 使用AK&SK初始化账号Client
//     * @param accessKeyId
//     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-qingdao",
                "LTAI4G1S14A2oFKe7URPpPQB", "8Tz84pEhGP6s9xIUkEBUCPikLLJ5ZS");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-qingdao");
        request.putQueryParameter("PhoneNumbers", "17603940501"); //目标手机号
        request.putQueryParameter("SignName", "ABC商城"); //签名名称
        request.putQueryParameter("TemplateCode", "SMS_211215101"); //短信模板code
        request.putQueryParameter("TemplateParam", "{\"code\":\"123456\"}");//模板中变量替换
        try {
            CommonResponse response = client.getCommonResponse(request);

            //{"Message":"OK","RequestId":"EC2D4C9A-0EAC-4213-BE45-CE6176E1DF23","BizId":"110903802851113360^0","Code":"OK"}
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();

            //用户登录名称 tanhua@1836512316159028.onaliyun.com
            //AccessKey ID LTAI4G1S14A2oFKe7URPpPQB
            //AccessKey Secret 8Tz84pEhGP6s9xIUkEBUCPikLLJ5ZS
        }
    }
}
